package de.ret_world.openrpgstudio.editor.script;

import de.ret_world.openrpgstudio.editor.Project;
import java.io.File;
import java.nio.file.Path;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.OneArgFunction;

/**
 * Helper Lua Library for easy lua scripting!
 *
 * @author Emu
 */
public class MainLib extends OneArgFunction {

    @Override
    public LuaValue call(LuaValue arg) {
        int i;
        switch (opcode) {
            case 0: {
                LuaValue t = tableOf();
                this.bind(t, MainLib.class, new String[]{"getScriptFolder"}, 1);
                env.set("Main", t);
                return t;
            }
            case 1: //getScriptFolder
                Path sf = Project.getInstance().getFolder("scripts");
                return valueOf(sf.toString()+File.separator);
            default:
                return error("bad opcode: " + opcode);
        }
    }
}
